package fr.epsi.activities.employe;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.*;
import com.example.MyLittleHotel.R;
import fr.epsi.BDD.BDD;

import java.sql.SQLException;
import java.util.Currency;

/**
 * Created by Florent Baudon on 15/05/2014.
 */
public class ConsulterEmployeActivity extends ListActivity implements View.OnClickListener {

    private BDD bdd;
    private Cursor cListInfos;
    private ImageButton ajouter;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.consulteremployelayout);

        ajouter = (ImageButton)findViewById(R.id.buttonadd);
        ajouter.setOnClickListener(this);

        try {
            bdd = new BDD();
            bdd.open(this);
            cListInfos = bdd.getEmployes();
        }catch (SQLException e){
            e.printStackTrace();
        }
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cListInfos, new String[]{"nom", "prenom"}, new int[]{android.R.id.text1, android.R.id.text2});
        setListAdapter(adapter);
    }

    public void onResume(){
        super.onResume();
        try {
            bdd = new BDD();
            bdd.open(this);
            cListInfos = bdd.getEmployes();
        }catch (SQLException e){
            e.printStackTrace();
        }
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cListInfos, new String[]{"nom", "prenom"}, new int[]{android.R.id.text1, android.R.id.text2});
        setListAdapter(adapter);
    }
    protected void onListItemClick (ListView l, View v, int position, long id){
        super.onListItemClick(l, v, position, id);
        TwoLineListItem tlli = (TwoLineListItem)v;

        Intent i = new Intent(this, FicheEmployeActivity.class);
        i.putExtra("nom", tlli.getText1().getText().toString());
        i.putExtra("prenom", tlli.getText2().getText().toString());
        startActivity(i);
    }

    public void onClick(View v) {

        Intent p = new Intent(this, AjouterEmployeActivity.class);
        startActivity(p);

        }
    }
